package com.my.cd.factory.methodFactory;

import com.my.cd.factory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 抽象披萨订单类：使用抽象方法来获取子类的实例
 */
@SuppressWarnings("all")
public abstract class OrderPizza {

    public OrderPizza() {
        Pizza pizza = null;
        String ordertype;
        do {
            ordertype = getType();// 读取类型
            pizza = createPizza(ordertype);
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }

    abstract Pizza createPizza(String orderType);//工厂方法主函数

    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("\n input pizza type:");
            return strin.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
